import Stages.GameStage
import Stages.StartStage
import Stages.StoreStage
import com.badlogic.gdx.ApplicationAdapter
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.backends.lwjgl.LwjglApplication
import com.badlogic.gdx.graphics.Color

fun main(args: Array<String>)
{
    LwjglApplication(MainPage(), config {
        width = 480
        height = 320
        useGL20 = true
        backgroundFPS = 30
        foregroundFPS = 120
        initialBackgroundColor = Color.GRAY
        resizable = false
        title = "MapDemo"
    })
}

var stageFlag = MainPage.STAGE_FLAG.START

class MainPage : ApplicationAdapter()
{
    private val startStage by lazy { StartStage() }
    private val gameStage by lazy { GameStage() }
    private val storeStage by lazy { StoreStage() }
    private val music by lazy { Gdx.audio.newMusic(Gdx.files.internal("music.ogg")) }
    
    
    override fun create()
    {
        music.isLooping = true
        music.play()
    }
    
    override fun render()
    {
        clear()

        when (stageFlag)
        {
            STAGE_FLAG.START ->
            {
                if (Gdx.input.inputProcessor != startStage)
                {
                    Gdx.input.inputProcessor = startStage
                }
                startStage.act()
                startStage.draw()
            }
            STAGE_FLAG.GAME ->
            {
                if (Gdx.input.inputProcessor != gameStage)
                {
                    Gdx.input.inputProcessor = gameStage
                }
                gameStage.act()
                gameStage.draw()
            }
            STAGE_FLAG.STORE ->
            {
                if (Gdx.input.inputProcessor != storeStage)
                {
                    Gdx.input.inputProcessor = storeStage
                }
                storeStage.act()
                storeStage.draw()
            }
        }
    }

    enum class STAGE_FLAG
    {
        START, GAME, STORE
    }
}


